package com.ldh.mod4j.businessdomain.generator.hibernate

import com.google.inject.Inject
import org.mod4j.dslcommon.generator.helpers.NameMapper
import org.mod4j.businessdomain.generator.helpers.BusinessClassHelpers
import com.ldh.mod4j.businessdomain.businessDomainDsl.BusinessClass
import org.mod4j.dslcommon.xpand.java.JavaComments
import com.ldh.mod4j.businessdomain.businessDomainDsl.BusinessDomainModel
import org.mod4j.dslcommon.generator.helpers.ModelHelpers
import org.mod4j.dslcommon.xpand.xml.XmlComments
import org.mod4j.dslcommon.generator.helpers.ProjectProperties

class HibernateDataLayerContext {
	@Inject extension XmlComments xmlComments
	
	def environmentprops(BusinessDomainModel model)'''
# Initially generated by Mod4j at «ModelHelpers::timestamp()»

##
# TODO: 
# Uncomment or add one of the Hibernate dialect properties below for the database in your environment.
# For an overview of the supported dialects by Hibernate see: http://docs.jboss.org/hibernate/core/3.5/api/org/hibernate/dialect/package-summary.html
##
#hibernate.dialect=org.hibernate.dialect.DB2Dialect
hibernate.dialect=org.hibernate.dialect.DerbyDialect
#hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
#hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
#hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

## 
# hibernate.hbm2ddl.auto = validate | update | create | create-drop
# Warning! The value 'update' is very convenient during development, but in general it is not recommended
# to be used in production environments.
##
hibernate.hbm2ddl.auto=update
	'''
	
	def sessionFactoryContext(BusinessDomainModel model)'''
<?xml version="1.0" encoding="UTF-8"?>
«xmlComments.extensionPointHeader("Mod4j BusinessDomainDsl generator: HibernateDatalayerContext.xtend", model)» 
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    
    <!-- hibernate wiring -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!--
            The "mappingResources" bean referenced is a list defined in the
            generated "applicationContext.xml" in "generated-resources".
        -->
        <property name="mappingResources" ref="mappingResources"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.use_query_cache">true</prop>
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            </props>
        </property>
        <property name="namingStrategy">
            <bean class="org.mod4j.runtime.hibernate.Mod4jNamingStrategy" />
        </property>
    </bean>
</beans>	
	'''
	
	def dataSourceContext(BusinessDomainModel model)'''
<?xml version="1.0" encoding="UTF-8"?>
«xmlComments.extensionPointHeader ("Mod4j BusinessDomainDsl generator: HibernateDatalayerContext.xtend", model)» 
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="dataSource"
        class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/«ProjectProperties::getApplicationName()»DS" />
        <property name="lookupOnStartup" value="false" />
        <property name="cache" value="true" />
        <property name="proxyInterface" value="javax.sql.DataSource" />
    </bean>
</beans>	
	'''
}